//
//  Target_Module1Service.swift
//  RouterDemo
//
//  Created by 刘康 on 2021/6/20.
//

import KKFoundation

/*
 {
  des: “获取Module1VC”
  url: "Module1://Module1/action1"
  params: ""
  return:UIViewController
 }
 {
  des: “获取Module1VC”
  url: "Module1://Module1/action2"
  params: "para1:String?, para2:Int?, para3:((String)->()), para4:String"
  return:UIViewController
 }
 {
  des: “获取Module1数据”
  url: "Module1://Module1/action3"
  params: "para1:String?, para2:((String)->())"
  return:UIViewController
 }
 */
class Target_Module1: BaseRouterTarget {
    override func handleAction(_ action: String, params: [String : Any]?) -> Any? {
        switch action {
        case "action1": // 简单返回控制器
            let vc = Module1ViewController()
            return vc
        case "action2": // 返回控制器并传参
            let para1 = params?["para1"] as? String
            let para2 = params?["para2"] as? Int
            let block = params?["para3"] as? ((String)->())
            let para4 = (params?["para4"] as? String) ?? ""
            let vc = Module1ViewController()
            vc.para1 = para1
            vc.para2 = para2
            vc.para3 = block
            vc.para4 = TestEnum(rawValue: para4)
            return vc
        case "action3": // 如果module2需要让module1请求一个接口,并将数据返回给module2
            let para1 = (params?["para1"] as? String) ?? ""
            let block = params?["para2"] as? ((String)->())
            Module1ViewModel.network(para1: para1, block: block)
           
        default:
            break
        }
        return nil
    }
}
